"""
Basic CLI interface for the RPN calculator

Commands:
q - Quit
c - Clear calculator

Available operations:
+ - Add
- - Minus
* - Multiply
/ - Divide
"""
import sys
from RPN import RPN


def main():
    calculator = RPN()
    userin = ""

    while userin.lower() != "q":
        userin = input("Enter an operator or number: ")
        if userin.lower() == "c":
            calculator.clear()
            print("Calculator cleared.")
        elif userin.lower() != "q":
            try:
                print("Result: " + str(calculator.next(userin.strip())))
                print("Remaining Operands: " + str(calculator.numstack))
            except (ValueError, ArithmeticError) as e:
                print(e)
        print()

    return 0

if __name__ == "__main__":
    sys.exit(main())